package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckgroupService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("checkgroup")
@Slf4j
public class CheckgroupController {

    @DubboReference
    private CheckgroupService checkgroupService;
    
    /**
     * @Author: 15041
     * @Date: 18:17 2021/1/18
     * @Parms: [queryPageBean]
     * @ReturnType: com.itheima.health.entity.Result
     *Description: 分页查询
    */
    @GetMapping("findByPage")
    public Result findByPage(QueryPageBean queryPageBean){
        log.info("检查组-分页查询controller层方法传参："+queryPageBean);
        PageResult pageResult = checkgroupService.findByPage(queryPageBean);
        log.info("检查组-分页查询controller层查询到的数据是："+pageResult);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS,pageResult);
    }
    
    /**
     * @Author: 15041
     * @Date: 18:17 2021/1/18
     * @Parms: []
     * @ReturnType: com.itheima.health.entity.Result
     *Description: 查询所有
    */
    @GetMapping("findAll")
    public Result findAll(){
        List<CheckGroup> list = checkgroupService.findGroupAll();
        log.info("检查组-查询所有controller层查到的数据是：{}",list);
        return new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,list);
    }

    /**
     * @Author: 15041
     * @Date: 18:17 2021/1/18
     * @Parms: []
     * @ReturnType: com.itheima.health.entity.Result
     *Description: 查询所有检查项
    */
    @GetMapping("findCheckitem")
    public Result findCheckitem(){
        log.info("检查组-分页查询controller层方法传参：");
        List<CheckItem> list = checkgroupService.findCheckitem();
        return new Result(true,MessageConst.QUERY_CHECKITEM_SUCCESS,list);
    }

    /**
     * @Author: 15041
     * @Date: 18:21 2021/1/18
     * @Parms: [id]
     * @ReturnType: com.itheima.health.entity.Result
     *Description: 根据id查询所有检查项
    */
    @GetMapping("findCheckIds")
    public Result findCheckIds(Integer id){
        log.info("检查组-根据id查询检查项controller层方法传参："+id);
        CheckGroup checkGroup = checkgroupService.findCheckIds(id);
        return new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }

    /**
     * @Author: 15041
     * @Date: 18:21 2021/1/18
     * @Parms: [checkGroup, checkitemIds]
     * @ReturnType: com.itheima.health.entity.Result
     *Description: 新增检查项
    */
    @PostMapping("add")
    public Result add(@RequestBody CheckGroup checkGroup , Integer[] checkitemIds){
        log.info("检查组-新增检查项controller层方法传参："+checkGroup+checkGroup);
        checkgroupService.add(checkGroup,checkitemIds);
        return new Result(true,MessageConst.ADD_CHECKGROUP_SUCCESS);
    }

    /**
     * @Author: 15041
     * @Date: 18:22 2021/1/18
     * @Parms: [checkGroup, checkitemIds]
     * @ReturnType: com.itheima.health.entity.Result
     *Description: 修改检查项
    */
    @PostMapping("update")
    public Result update(@RequestBody CheckGroup checkGroup , Integer[] checkitemIds){
        log.info("检查组-修改检查项controller层方法传参："+checkGroup+"检查项id："+checkitemIds);
        checkgroupService.update(checkGroup,checkitemIds);
        return new Result(true,MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }

    /**
     * @Author: 15041
     * @Date: 18:22 2021/1/18
     * @Parms: [id]
     * @ReturnType: com.itheima.health.entity.Result
     *Description: 删除检查项
    */
    @PostMapping("delete")
    public Result delete(Integer id){
        log.info("检查组-根据id删除controller层方法传参："+id);
        checkgroupService.delete(id);
        return new Result(true,MessageConst.DELETE_CHECKGROUP_SUCCESS);
    }

}
